package hrms.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import hrms.entity.Wanted;
import hrms.service.WantedServiceImpl;
import hrms.util.LogUtil;
import hrms.util.Result;

@Controller
@RequestMapping("/wanted")
public class WantedController {
	
	@Resource(name="wantedService")
	private WantedServiceImpl WantedService;
	
	@ExceptionHandler
	public String exHandle(Exception ex, HttpServletRequest req) {
		LogUtil.saveEx(ex);
		return "error";
	}
	
	@ResponseBody
	@RequestMapping("/loadWanted.sls")
	public Result<List<Wanted>> executeA(HttpServletRequest req ,HttpServletResponse res){
		String page = req.getParameter("page");
		Result<List<Wanted>> result = WantedService.findByPage(page,res);
		return result;
	}
	
	@ResponseBody
	@RequestMapping("/wantedPage.sls")
	public Result<Map<String,Integer>> executeB2(HttpServletRequest req){
		Result<Map<String,Integer>> result = WantedService.pageTotal(req);
		return result;
	}
	
	
	@ResponseBody
	@RequestMapping("/addWanted.sls")
	public Result<Object> executeB3(HttpServletRequest req){
		String wjob = req.getParameter("wjob");
		String wnum = req.getParameter("wnum");
		String wplace = req.getParameter("wplace");
		String wtime = req.getParameter("wtime");
		String wdate = req.getParameter("wdate");
		return WantedService.addWanted( wjob,  wnum, wplace, wtime,wdate);
	}
	
	/*
	@ResponseBody
	@RequestMapping("/updateWanted.sls")
	public Result<Object> executeB4(HttpServletRequest req){
		String WantedId = req.getParameter("WantedId");
		String WantedName = req.getParameter("WantedName");
		String WantedAge = req.getParameter("WantedAge");
		String WantedSex = req.getParameter("WantedSex");
		String WantedJob = req.getParameter("WantedJob");
		String WantedDept = req.getParameter("WantedDept");
		return WantedService.uppdateWanted(WantedId, WantedName,  WantedSex, WantedAge, WantedJob, WantedDept,req);
	}
	*/
	@ResponseBody
	@RequestMapping("/changeState.sls")
	public Result<Object> executeI(HttpServletRequest req){
		String WantedId = req.getParameter("id");
		return WantedService.changeState(WantedId, req);
	}
	
	/*
	@ResponseBody
	@RequestMapping("/showWanted.sls")
	public Result<Wanted> executeII(HttpServletRequest req){
		String WantedId = req.getParameter("WantedId");
		return WantedService.findWanted(WantedId, req);
	}
	*/
	
	@ResponseBody
	@RequestMapping("/searchWanted.sls")
	public Result<List<Wanted>> executeAA(HttpServletRequest req ,HttpServletResponse res){
		String name = req.getParameter("name");
		if(name == null || name == ""){
			return WantedService.findByPage("1",res);
		}
		return WantedService.search(name);
	}
	
}